<?
    class MessageManager {
        static function GetMessages() {
            $rows = DBM::FetchAllRows("SELECT * FROM messages WHERE displayuntil > UNIX_TIMESTAMP() ORDER BY createdon DESC;");
            return $rows;
        }
        static function HasMessages() {
            return (DBM::CountRows("SELECT * FROM messages WHERE displayuntil > UNIX_TIMESTAMP();") > 0);
        }
        static function DisplayMessages() {
            echo "<ul class='messagelist'>";
            foreach (self::GetMessages() as $row) {
                $message = new MiniMessage($row['message'] . " <span style='font-size:7pt; color:gray; white-space:nowrap;'>( " . date("n/j/y",$row['createdon']) . " )</span> ",$row['severity']);
                echo $message;
            }
            echo "</ul>";
        }
        
        static function Initialize() {
            if (!isset($_SESSION['messages']))
                session_register("messages");
        }
        static function QueueMessage(Message $message) {
            $_SESSION['messages'][] = $message;
        }
    }
?>
